package com.zxy.ziems.server.alarm.convertor;

import com.zxy.ziems.server.alarm.pojo.dto.*;
import com.zxy.ziems.server.alarm.pojo.entity.*;
import com.zxy.ziems.server.alarm.pojo.vo.*;
import com.zxy.ziems.server.device.pojo.entity.DataTypeEntity;
import com.zxy.ziems.server.device.pojo.entity.DeviceEntity;
import com.zxy.ziems.server.device.pojo.entity.DevicePropertyEntity;
import com.zxy.ziems.server.device.pojo.entity.DeviceTypeEntity;
import com.zxy.ziems.server.domain.Role;
import com.zxy.ziems.server.domain.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author chdzq
 * @create 2023/3/28
 */
@Mapper(
)
public interface AlarmConvertor {
    AlarmConvertor INSTANCE = Mappers.getMapper(AlarmConvertor.class);


    //告警类型
    AlarmTypeEntity typeDTOConvert2DO(AlarmTypeDTO dto);

    List<AlarmTypeVO> typeDOListConvert2VOList(List<AlarmTypeEntity> list);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "updateTime", source = "entity.updateTime")
    AlarmTypeVO typeDOConvert2VO(AlarmTypeEntity entity, User updateUser);


    //记录
    @Mapping(target = "deviceDataTypeId", source = "devicePropertyId")
    AlarmRecordEntity alarmRecordDTOConvertor2DO(AlarmRecordEvent event);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "alarmPropertyName", source = "devicePropertyEntity.name")
    AlarmRecordVO alarmRecordDOConvertor2VO(AlarmRecordEntity entity,
                                            DeviceEntity device,
                                            DevicePropertyEntity devicePropertyEntity,
                                            AlarmTypeEntity alarmType,
                                            User processUser);

    @Mapping(target = "id", source = "entity.id")
    AlarmRecordDeviceVO alarmRecordDOConvertorDeviceVO(AlarmRecordEntity entity);

    //处理记录
    AlarmProcessRecordEntity processRecordDTOConvertor2DO(AlarmProcessRecordDTO dto);


    List<AlarmRuleVO> ruleDOListConvert2VOList(List<AlarmRuleEntity> list);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "roleName", source = "role.roleName")
    @Mapping(target = "roleId", source = "entity.roleId")
    AlarmRuleRoleVO alarmRuleRoleDOConvertor2VO(AlarmRuleRoleEntity entity, Role role);


    /**
     * 告警规则范围
     *
     * @param entity
     * @param deviceTypeEntity
     * @param alarmTypeEntity
     * @return
     */
    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "deviceTypeName", source = "deviceTypeEntity.name")
    @Mapping(target = "alarmTypeName", source = "alarmTypeEntity.name")
    AlarmRuleRangeVO alarmRuleTypeDOConvertor2VO(AlarmRuleRangeEntity entity, DeviceTypeEntity deviceTypeEntity, AlarmTypeEntity alarmTypeEntity);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "updateUserName", source = "user.userName")
    @Mapping(target = "status", source = "entity.status")
    @Mapping(target = "updateUserId", source = "entity.updateUserId")
    @Mapping(target = "updateTime", source = "entity.updateTime")
    AlarmRuleVO alarmRuleDOConvertor2VO(AlarmRuleEntity entity, User user);

    AlarmTypeCountVO alarmTypeCountDOConvertor2VO(AlarmTypeCountDTO entity);

    AlarmDealCountVO alarmDealCountDOConvertor2VO(AlarmDealCountDTO entity);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "alarmPropertyName", source = "dataTypeEntity.name")
    AlarmRecordVO alarmRecordDOConvertor2VO(AlarmRecordEntity entity, DeviceEntity device,
                                            DataTypeEntity dataTypeEntity, AlarmTypeEntity alarmType, User processUser);


    List<AlarmTypeOptionVO> typeDOConvert2VOList(List<AlarmTypeEntity> list);
}
